package com.spzx.product.api.factory;

import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteBrandService;
import com.spzx.product.api.domain.Brand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

public class RemoteBrandFallbackFactory implements FallbackFactory<RemoteBrandService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteBrandFallbackFactory.class);

    @Override
    public RemoteBrandService create(Throwable cause) {
        log.info("远程调用【"+ ServiceNameConstants.PRODUCT_SERVICE+"】服务出现问题了:");
        return new RemoteBrandService(){
            @Override
            public R<List<Brand>> getBrandAllList(String source) {
                return R.fail("调用查询全部品牌降级了 - "+cause.getMessage());
            }
        };
    }
}
